package com.ruoyi.web.controller.linkage.mechanismType;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.mechanismType.domain.MechanismType;
import com.ruoyi.mechanismType.service.IMechanismTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备类型Controller
 *
 * @author pengjie
 * @date 2023-12-21
 */
@RestController
@RequestMapping("/mechanism/type")
public class MechanismTypeController extends BaseController
{
    @Autowired
    private IMechanismTypeService mechanismTypeService;

    /**
     * 查询设备类型列表
     */
    @PreAuthorize("@ss.hasPermi('mechanism:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(MechanismType mechanismType)
    {
        startPage();
        List<MechanismType> list = mechanismTypeService.selectMechanismTypeList(mechanismType);
        return getDataTable(list);
    }
    /**
     * 查询设备类型列表树
     */
    @PreAuthorize("@ss.hasPermi('mechanism:type:list')")
    @GetMapping("/queryTreeData")
    public TableDataInfo queryTreeData()
    {
        startPage();
        List<MechanismType> list = mechanismTypeService.selectMechanismTypequeryTreeData();
        return getDataTable(mechanismTypeService.getDto(list));
    }

    /**
     * 导出设备类型列表
     */
    @PreAuthorize("@ss.hasPermi('mechanism:type:export')")
    @Log(title = "设备类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MechanismType mechanismType)
    {
        List<MechanismType> list = mechanismTypeService.selectMechanismTypeList(mechanismType);
        ExcelUtil<MechanismType> util = new ExcelUtil<MechanismType>(MechanismType.class);
        util.exportExcel(response, list, "设备类型数据");
    }

    /**
     * 获取设备类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('mechanism:type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(mechanismTypeService.selectMechanismTypeById(id));
    }

    /**
     * 新增设备类型
     */
    @PreAuthorize("@ss.hasPermi('mechanism:type:add')")
    @Log(title = "设备类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MechanismType mechanismType)
    {
        return toAjax(mechanismTypeService.insertMechanismType(mechanismType));
    }

    /**
     * 修改设备类型
     */
    @PreAuthorize("@ss.hasPermi('mechanism:type:edit')")
    @Log(title = "设备类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MechanismType mechanismType)
    {
        return toAjax(mechanismTypeService.updateMechanismType(mechanismType));
    }

    /**
     * 删除设备类型
     */
    @PreAuthorize("@ss.hasPermi('mechanism:type:remove')")
    @Log(title = "设备类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(mechanismTypeService.deleteMechanismTypeByIds(ids));
    }
}
